Skip to content

WS-4 M1/M4:内核行为同步与 Skills 化 - #2

Merged
BSTester merged 4 commits into
mainfrom
ws-4-m1-m4
Jul 6, 2026
Merged

WS-4 M1/M4:内核行为同步与 Skills 化#2
BSTester merged 4 commits into
mainfrom
ws-4-m1-m4

Conversation

@BSTester

@BSTester BSTester commented Jul 6, 2026

Copy link
Copy Markdown
Owner

背景

WS-4 Stage 4 第二段:M1 内核行为同步 + M4 Skills 化。基于 ws-4-stage4-m0 分支继续,和 M0 PR 解耦,便于独立 review。

M1 内核同步

  • grounded Sentiment Analyst:舆情报告要求输出“数据快照”,并把证据快照写入 grounded_evidence
  • Research Manager / Trader / Portfolio Manager 结构化输出:三类节点提示词增加 STRUCTURED_OUTPUT;最终 final_state.structured_report 统一生成五级评级、5 个分项、证据、阶段日志、反思。
  • 五级评级:structured_outputs.py 将 BUY/HOLD/SELL/strong buy/sell 映射为 1-5 评级,并贯穿综合与分项。
  • 决策日志反思:同标的历史完成记录会注入 previous_decision_reflection,并保存在最终 reflection
  • 检查点续跑:新增 JSON checkpoint,成功阶段写入,重跑同 analysis_id 时恢复最近成功字段。
  • v0.2.5 行为对齐:保留 4 Analyst + Bull/Bear + Research Manager + Trader + Risk/Portfolio recommendation 流,不复活 trading_executor / intraday_trader。
  • TRADINGAGENTS_* 环境变量:新增 TRADINGAGENTS_LLM_PROVIDERTRADINGAGENTS_DEEP_LLMTRADINGAGENTS_QUICK_LLMTRADINGAGENTS_OPENAI_BASE_URL、provider API key 自动探测;兼容原 env。
  • 标的代码路径穿越加固:分析日志/checkpoint 路径使用 safe path component。

M4 Skills 化

  • 新增 SkillProvider / RoutedSkillProvider 抽象与 SkillRegistry
  • 实现 6 个内部技能:market-datatechnical-indicatorsfundamentalsnewssocial-sentimentmarket-detection
  • 复用现有 yfinance / akshare / baostock / alpha_vantage / google / openai 适配器,dataflows 回退链补入 baostock。
  • 现有 LangChain tools 改为经 Skills registry 调用,前端仍不直调数据源。
  • 新增 GET /api/skills/health/ws/skills-health 健康推送。
  • M4-S9 codex-plugins.dev 复核按指令跳过。

非目标 / 约束

  • 未实现交易、下单、排行榜。
  • 未恢复 Futu / Trading Executor / intraday trader。
  • Portfolio/Risk 输出止步于建议。
  • M2 对话后端尚未开始。

验证

  • python -m compileall -q web/backend tradingagents
  • Skills registry 纯 Python 健康快照检查通过(6 skills)。
  • 删除/下单/排行榜关键字扫描未发现可执行引用。
  • FastAPI route import 检查受当前运行时未安装 fastapi 影响,未作为本地验证项。

Refs WS-4

Copilot AI added 4 commits July 6, 2026 07:29
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 6, 2026 10:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR continues WS-4 Stage 4 work by aligning backend “kernel” behavior with the new non-trading analysis flow, introducing an internal Skills registry (with health endpoints) as the abstraction layer over dataflows, and removing intraday trading / leaderboard / order-execution related code paths.

Changes:

  • Introduces SkillRegistry / RoutedSkillProvider and routes existing LangChain tools through the Skills layer, plus adds /api/skills/health and uses the existing /ws/skills-health.
  • Adds structured report generation (1–5 rating mapping), grounded evidence snapshots, previous-decision reflection injection, and JSON checkpoint resume for long runs.
  • Removes intraday scheduler/executor, Futu trading wrappers, snapshots/leaderboard routes & models, and updates prompts/schemas to enforce “recommendations only”.

Reviewed changes

Copilot reviewed 63 out of 64 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
web/backend/tests/test_scheduler_recovery.py Removed intraday scheduler recovery test script.
web/backend/services/user_intraday_scheduler.py Removed multi-user intraday scheduler manager.
web/backend/services/user_config_cache.py Drops intraday/Futu/trading-executor fields from cached config dict.
web/backend/services/task_executor.py Removes trading-executor + Futu config propagation from scheduled task execution.
web/backend/services/snapshot_scheduler.py Removed daily account snapshot scheduler service.
web/backend/services/skills/registry.py Adds Skills registry defining 6 internal skills and provider routing.
web/backend/services/skills/base.py Adds skill provider contracts + RoutedSkillProvider health/execute behavior.
web/backend/services/skills/init.py Exposes get_skill_registry() API.
web/backend/services/prompt_loader.py Renames default prompt to analysis agent; keeps intraday alias for compatibility.
web/backend/services/intraday_scheduler.py Removed per-user intraday scheduler implementation.
web/backend/services/futu_async_wrapper.py Removed async wrappers for Futu trading API functions.
web/backend/schemas.py Removes trading executor / intraday access / leaderboard fields from API schemas; updates default agent type.
web/backend/routes/user_management_routes.py Removes intraday-access field & related admin endpoint wiring.
web/backend/routes/user_leaderboard_routes.py Removes user leaderboard toggle API.
web/backend/routes/user_config_routes.py Removes trading executor + Futu config fields from user config endpoints.
web/backend/routes/skills_routes.py Adds /api/skills/health route guarded by active-user auth.
web/backend/routes/scheduled_task_routes.py Removes trading executor + Futu config from scheduled task creation.
web/backend/routes/public_leaderboard_routes.py Removes public leaderboard APIs (snapshots/positions/decisions).
web/backend/routes/prompt_routes.py Uses generated variable documentation instead of reading intraday workflow file; import cleanup.
web/backend/routes/leaderboard_routes.py Removes analysis leaderboard endpoint.
web/backend/routes/analysis_routes.py Removes trading-executor config propagation; removes execution report rendering; clarifies “recommendations only”.
web/backend/routes/account_snapshot_routes.py Removes account snapshot APIs.
web/backend/routes/init.py Adds skills_routes to routes package exports.
web/backend/models.py Removes intraday/leaderboard/trading-executor models/fields; updates prompt template agent_type comment.
web/backend/migrations/add_llm_providers_models.py Updates default OpenAI provider metadata and default models list.
web/backend/migrations/005_update_tool_descriptions_english.py Removes trading tool description for place_futu_order.
web/backend/migrations/004_update_tool_descriptions_chinese.py Removes trading tool description for place_futu_order.
web/backend/migrations/003_init_default_prompts.py Initializes default prompt templates using new analysis agent type and prompt function.
web/backend/database.py Updates model import list used for table registration (removes intraday-related models).
web/backend/auth_routes.py Removes require_intraday_access dependency.
web/backend/app.py Removes intraday/leaderboard/snapshot startup logic and route wiring; adds skills router; updates app description.
web/backend/analysis_task.py Adds provider-aware API key resolution, checkpoint resume/save, safe path joins, grounded evidence, stage logs, structured report build, and previous-decision reflection injection.
tradingagents/utils/structured_outputs.py Adds structured report helpers (rating mapping, evidence snapshot, previous decision reflection).
tradingagents/utils/security.py Adds safe_join / safe_path_component to harden filesystem artifact paths.
tradingagents/utils/checkpoints.py Adds JSON checkpoint persistence helpers.
tradingagents/utils/init.py Adds utils package marker.
tradingagents/graph/trading_graph.py Removes trading executor node; wires provider API keys into LLM constructors; adds safe logging path; configures conditional logic with config values.
tradingagents/graph/setup.py Removes trading executor workflow edges; keeps recommendation-only flow.
tradingagents/graph/propagation.py Extends initial state with structured report fields + previous decision reflection.
tradingagents/graph/conditional_logic.py Removes conditional logic for trading executor tool loops.
tradingagents/default_config.py Adds TRADINGAGENTS_* env support and provider API key fields; updates default base URL and model defaults.
tradingagents/dataflows/interface.py Adds baostock as a vendor option and extends method mappings / fallback order.
tradingagents/agents/utils/tool_registry.py Restricts tool registry to read-only tools (removes Futu trading tooling registration).
tradingagents/agents/utils/technical_indicators_tools.py Routes technical indicator tool through Skills registry.
tradingagents/agents/utils/news_data_tools.py Routes news tools through Skills registry (but see review comments re: insider transactions routing).
tradingagents/agents/utils/fundamental_data_tools.py Routes fundamentals tools through Skills registry.
tradingagents/agents/utils/core_stock_tools.py Routes OHLCV data tool through Skills registry (but see review comments re: date window contract).
tradingagents/agents/utils/agent_states.py Adds structured report / reflection / evidence fields; removes execution report field.
tradingagents/agents/trader/trading_executor.py Removes trading execution agent implementation.
tradingagents/agents/trader/trader.py Adds previous decision reflection injection and structured output requirements; reinforces “no orders”.
tradingagents/agents/trader/intraday_trader_workflow.txt Removes intraday trading workflow document.
tradingagents/agents/trader/intraday_trader_default_prompt.txt Removes default intraday trading prompt file.
tradingagents/agents/managers/risk_manager.py Adds structured report build + reflection; injects previous decision reflection (but see review comment re: fundamentals sourcing bug).
tradingagents/agents/managers/research_manager.py Adds structured output requirements and reflection block propagation.
tradingagents/agents/analysts/social_media_analyst.py Adds grounded evidence snapshot generation (but see review comment re: overwriting evidence).
scripts/init_llm_config.py Updates default provider/model configuration data used for DB init.
.gitignore Ignores local env files more broadly; keeps .env.example.
.env.local Removes committed local env file (secrets).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -15,6 +16,7 @@ def risk_manager_node(state) -> dict:
fundamentals_report = state["news_report"]
Comment on lines +60 to +65
"grounded_evidence": evidence_snapshot(
ticker=ticker,
as_of=current_date,
report=report,
sources=["get_news", "social-sentiment"],
) if report else state.get("grounded_evidence", []),
Comment on lines +121 to +125
actions={
"sentiment": lambda ticker, start_date, end_date, **_: _route_to_vendor(
"get_news", ticker, start_date, end_date
),
},
Comment on lines +101 to +106
actions={
"company": lambda ticker, start_date, end_date, **_: _route_to_vendor(
"get_news", ticker, start_date, end_date
),
"global": lambda curr_date=None, look_back_days=7, limit=5, **_: _route_to_vendor("get_global_news", curr_date or datetime.now(timezone.utc).date().isoformat(), look_back_days, limit),
},
str: A report of insider transaction data
"""
return route_to_vendor("get_insider_transactions", ticker, curr_date)
return get_skill_registry().execute("news", "company", ticker=ticker, start_date=curr_date, end_date=curr_date)
"historical",
symbol=symbol,
curr_date=end_date,
look_back_days=max(1, (datetime.strptime(end_date, "%Y-%m-%d").date() - datetime.strptime(start_date, "%Y-%m-%d").date()).days),
@BSTester
BSTester merged commit b13caf4 into main Jul 6, 2026
1 check passed
@BSTester
BSTester deleted the ws-4-m1-m4 branch July 7, 2026 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants